home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1994 by Jon Dart. All Rights Reserved.
-
- // Stand-alone DOS executable to test the search engine
-
- #include "board.h"
- #include "movegen.h"
- #include "search.h"
- #include "options.h"
- #include "movearr.h"
- #include "notation.h"
- #include "timectrl.h"
- extern "C"
- {
- #include <string.h>
- #include <ctype.h>
- #include <assert.h>
- };
- #include <fstream.h>
- #include <iostream.h>
- #include <strstrea.h>
- #include <ctype.h>
- #include <time.h>
-
- Options *global_options = NULL;
- Move_Array *game_moves = NULL;
- int count = 0;
-
- static Move search(Board &board, Search_Limit limit,
- Search_Type type, Search::Statistics &stats)
- {
- Search searcher;
- global_options = new Options();
- game_moves = new Move_Array();
-
- Time_Info ti(type,limit);
- Move move = searcher.find_best_move(board, ti,
- stats, Move::NullMove(), False );
-
- ExtendedMove emove(board,move);
- char move_text[20];
- Notation::Image(board, emove, move_text);
- cout << "search:";
- cout << '\t' << move_text << "\t" << stats.elapsed_time <<
- " seconds.\t" << stats.num_moves << " moves.\t" <<
- stats.num_pos << " positions.";
-
- delete game_moves;
- delete global_options;
- return (Move)emove;
- }
-
- int main(int argc, char **argv)
- {
- Board board;
- Search_Limit limit;
- Search_Type type = Fixed_Ply;
- limit.max_ply = 2;
- int arg = 1;
-
- if (argc ==1)
- {
- cerr << "Usage: testsrc [-t seconds] [-p plies] position" << endl;
- return -1;
- }
- else
- {
- if (*(argv[arg]) == '-')
- {
- char c = tolower(*(argv[arg]+1));
- switch (c)
- {
- case 'p':
- type = Fixed_Ply; break;
- case 't':
- type = Time_Limit; break;
- default:
- cerr << "Usage: testsrc [-t seconds] [-p plies] position" << endl;
- return -1;
- }
- ++arg;
- if (argc <= 2)
- {
- cerr << "Usage: testsrc [-t seconds] [-p plies] position" << endl;
- return -1;
- }
- if (type == Fixed_Ply)
- limit.max_ply = atoi(argv[arg]);
- else
- {
- limit.seconds = atol(argv[arg]);
- }
- ++arg;
- }
-
- ifstream pos_file( argv[arg], ios::in);
- char buf[256];
- if (pos_file.good())
- {
- while (!pos_file.eof())
- {
- pos_file.getline(buf,256);
- if (!pos_file)
- {
- cout << "Bad format!" << endl;
- return -1;
- }
- if (strncmp(buf,"svfe",4)==0)
- {
- istrstream s(buf+5);
- s >> board;
- }
- else if (strncmp(buf,"echo",4)==0)
- {
- cout << buf+4 << endl;
- continue;
- }
- else if (strncmp(buf,"noop",4)==0)
- continue;
- else if (strncmp(buf,"srch",4)==0)
- {
- Move moves[10];
- int move_count = 0;
- for (char *p = buf+5;*p;)
- {
- while (isspace(*p) && *p != '\0') ++p;
- if (*p == '\0')
- break;
- char tmp[10];
- int i = 0;
- char *q = tmp;
- while (!isspace(*p) && *p != '+' && *p != '\0' && i < 10)
- {
- *q++ = *p++;
- ++i;
- }
- *q = '\0';
- Move m = Notation::Value(board,board.Side(),tmp);
- if (!m.IsNull())
- {
- assert(move_count < 10);
- moves[move_count++] = m;
- }
- if (*p == '+') ++p;
- }
- ++count;
- Search::Statistics stats;
- Move m = search(board,limit,type,stats);
- int correct = 0;
- for (int i = 0; i < move_count; ++i)
- {
- if (moves[i] == m)
- {
- ++correct; break;
- }
- }
- if (correct)
- cout << "\t++ correct" << endl;
- else
- cout << "\t** error" << endl;
-
- for (int j = 0; j < Constants::MaxPly; ++j)
- {
- char buf[30];
- Move m = stats.best_line[j];
- if (m.IsNull())
- break;
- Notation::Image(board,m,buf);
- cout << buf << " ";
- board.MakeMove(ExtendedMove(board,m));
- }
- cout << endl;
- }
- else if (strncmp(buf,"rtrn",4)==0)
- break;
- else
- {
- cout << "Warning: unrecognized command: " << buf << endl;
- }
-
- char c;
- while (!pos_file.eof())
- {
- c = pos_file.get();
- if (!isspace(c) && c != '\n')
- {
- if (!pos_file.eof())
- pos_file.putback(c);
- break;
- }
- }
- }
- pos_file.close();
- }
- else
- {
- cout << "file not found: " << argv[arg] << endl;
- return -1;
- }
- }
-
- return 0;
- }
-